package com.itheima.app.controller.pmsController;

import com.itheima.app.manager.pmsManager.ProductAttributeManager;
import com.itheima.commons.PageBean;
import com.itheima.commons.R;
import com.itheima.domain.db.pms.PmsProductAttribute;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author yin
 * @date 2022/10/13 16:07
 */

@RestController
public class ProductAttributeController {

    @Autowired
    ProductAttributeManager productAttributeManager;

    //添加商品属性信息
    @PostMapping("/productAttribute/create")
    public R addProductAttribute(@RequestBody PmsProductAttribute pmsProductAttribute) {
        return productAttributeManager.addProductAttribute(pmsProductAttribute);
    }

    //批量删除商品属性
    @PostMapping("/productAttribute/delete")
    public R deleteProductAttribute(Integer[] ids) {

        return productAttributeManager.deleteProductAttribute(ids);
    }

    //根据分类查询属性列表或参数列表
    @GetMapping("/productAttribute/list/{cid}")
    public R listCid(@PathVariable("cid") Integer cid,
                     @RequestParam(defaultValue = "1") Integer pageNum,
                     @RequestParam(defaultValue = "5") Integer pageSize,
                     @RequestParam Integer type){
        PageBean result = productAttributeManager.listCid(cid,pageNum,pageSize,type);
        return R.ok(result);
    }

    //修改商品属性信息
    @PostMapping("/productAttribute/update/{id}")
    public R updateProductAttribute(@PathVariable Integer id, @RequestBody PmsProductAttribute pmsProductAttribute) {
        return productAttributeManager.updateProductAttribute(id, pmsProductAttribute);
    }


    //根据商品分类的id获取商品属性及属性分类
    @GetMapping("/productAttribute/attrInfo/{productCategoryId}")
    public R getById(@PathVariable Integer productCategoryId){

        return productAttributeManager.getById(productCategoryId);
    }

    //查询单个商品属性
    @GetMapping("/productAttribute/{id}")
    public R getProductAttrById(@PathVariable Integer id){
        return productAttributeManager.getProductAttrById(id);
    }
}
